<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb clearfix">

      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>导出访客记录</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="GET" action="${ctx.host}/visitor-records/export" data-validate = "true">
      <c:if test="${empty currentPrincipal.site}">
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">门店</label>
          <div class="col-xs-6" style="width: 50%;">
            <select name="siteId" class="form-control select2">
              <option value="">全部门店</option>
              <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                <option value = "${site.id}">${site.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </c:if>
      
      <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">接待人</label>
          <div class="col-xs-6 pull-left">
             <select name="receiverId" class="select2 form-control">
              <option value=""></option>
              <c:forEach var="staff" items="${persist.staff(currentPrincipal.id)}">
                <option value="${staff.id}">${staff.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      
      <div class="modal-body">
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">开始日期</label>
          <div class="col-xs-6" style="width: 50%;">
            <input type="text" class="form-control beginDate" name="begin" data-validate = "required"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">结束日期</label>
          <div class="col-xs-6" style="width: 50%;">
            <input type="text" class="form-control endDate" name="end" data-validate = "required"/>
          </div>
        </div>
      </div>

      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>

    </form>

  </div>

</div>

<script type="text/javascript">
  $(function() {
    $('select[name="siteId"]').select2({
          placeholder : '请选择门店',
          minimumResultsForSearch : -1,
          allowClear : true,
          width: '100%'
    });
    
    $('select[name="receiverId"]').select2({
        placeholder : '请选择接待人',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
  });
    
    $('.beginDate').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month',
        startDate: '2016-05-11',
        endDate: '${today}'
      }).on('hide', function(event) {  
        event.preventDefault();  
        event.stopPropagation();  
        var startTime = event.date;  
        $(".endDate").datetimepicker('setStartDate',startTime);  
        $(".endDate").val("");  
    });
    
    $(".endDate").datetimepicker({  
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month',
        startDate: '2016-05-11',
        endDate: '${today}'
    }).on('hide', function(event) {  
        event.preventDefault();  
        event.stopPropagation();  
        var endTime = event.date;  
        $(".beginDate").datetimepicker('setEndDate',endTime);  
    });
  })
</script>
